package com.luhai.shipmentscheck.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.luhai.shipmentscheck.R;
import com.luhai.shipmentscheck.config.Constants;
import com.luhai.shipmentscheck.manager.SharedPreferencesManager;
import com.luhai.shipmentscheck.widget.TopBar;

import static com.luhai.shipmentscheck.config.Constants.IP;
import static com.luhai.shipmentscheck.config.Constants.URL_HEAD;

public class SettingActivity extends BaseActivity implements TopBar.OnTopBarClickListener {

    private TopBar topBar;

    private EditText et_cl_id;

    @Override
    public void widgetClick(View v) {

    }

    @Override
    protected void init() {

    }

    @Override
    public int bindLayout() {
        return R.layout.activity_setting;
    }

    @Override
    public void initView(View view) {

        topBar = findViewById(R.id.topBar);
        et_cl_id = findViewById(R.id.et_cl_id);
        et_cl_id.setText( SharedPreferencesManager.getSingleTon().getSharedPreference(Constants.SP_SERVER_IP,"192.168.1.100").toString());
        topBar.setImageResource(false, R.drawable.correct);
        topBar.setText("服务器地址");
    }

    @Override
    public void setListener() {

        topBar.setOnTopBarClickListener(this);
    }

    @Override
    public void doBusiness(Context mContext) {

    }

    @Override
    public void onTopBarClick(boolean isLeft) {
        if (isLeft) {
            finish();
        } else {
            SharedPreferencesManager.getSingleTon().put(Constants.SP_SERVER_IP, et_cl_id.getText().toString());
            IP = SharedPreferencesManager.getSingleTon().getSharedPreference(Constants.SP_SERVER_IP, "192.168.1.100").toString();
            URL_HEAD = "http://" + IP + ":8081/";
            Constants.URL_GET_SHIPMENTS_CHECK_INFO=URL_HEAD + "/GetShipmentCheckOrderInfo";
            Constants.URL_GET_CL_ID_LIKE_LIST = URL_HEAD + "/GetLikeList";
            finish();
        }
    }
}
